package calendar.messages;

import calendar.Event;
import edu.gmu.middleware.Message;
import edu.gmu.streams.BlockInputStream;
import edu.gmu.streams.BlockOutputStream;
import java.io.IOException;

/* this class represents a calendar event */
import java.util.ArrayList;
public class RetrieveResponse implements Message
{ 
    public ArrayList events;

    public RetrieveResponse()
    {
        this.events = null;
    }


    public void marshal(BlockOutputStream stream) throws IOException
    {
        boolean isNull = (this.events == null);
        stream.writeBoolean(isNull);
        if( isNull == false )
        {
            stream.writeInt( this.events.size() );
            for (int i = 0; i < events.size(); i++)
            {
                Event event = (Event)events.get(i);
                event.marshal(stream);
            }
        }
    }

    public void unmarshal(BlockInputStream stream) throws IOException
    {
        boolean isNull = stream.readBoolean();
        if( isNull == false )
        {
            int size = stream.readInt();
            this.events = new ArrayList();
            for (int i = 0; i < size; i++)
            {
                Event event = new Event();
                event.unmarshal(stream);
                this.events.add(event);
            }
        }
    }
}
